<?php
apf_require_class('APF_Controller');
apf_require_class('Solr_Bll_AppBiz');
apf_require_class('Solr_Bll_ReportBiz');
apf_require_class('Solr_Util_PageBar');
class Report_ListController extends APF_Controller {

    public static function build_uri() {
        $base_domain = APF::get_instance()->get_config("base_domain");
        $schema = APF::get_instance()->get_request()->is_secure() ? "https" : "http";
        $url = "{$schema}://{$base_domain}/report/list/";
        return $url;
    }

    public function handle_request() {

        $request = APF::get_instance()->get_request();
        $params = $request->get_parameters();
        $page=max(intval($params['page']),1);
        $num = 50;

        $attr=array();
        if($params['datei'])$attr['datei']=$params['datei'];
        if($params['hostname_id'])$attr['hostname_id']=$params['hostname_id'];
        if($params['webapp_id'])$attr['webapp_id']=$params['webapp_id'];

        $report_list=Solr_Bll_ReportBiz::get_instance()->get_reports_list($attr,$page,$num);
        $report_count=Solr_Bll_ReportBiz::get_instance()->get_reports_count($attr);
        $request->set_attribute('report_list',$report_list);

        $app_biz=Solr_Bll_AppBiz::get_instance();

        $hostnames=$app_biz->get_all_hostname();
        $request->set_attribute('hostnames',$hostnames);

        $webapps=$app_biz->get_all_webapp();
        $request->set_attribute('webapps',$webapps);

        $var="datei=".$params['datei']."&hostname_id=".$params['hostname_id']."&webapp_id=".$params['webapp_id'];
        $page_bar=Solr_Util_PageBar::get_page_bar(Report_ListController::build_uri(),$report_count,$page,$num,$var,'page',9);
        $request->set_attribute('page_bar',$page_bar);

        $request->set_attribute('params',$params);
        return 'Report_List';
    }
}

